import System.Reflection
import Castle.MonoRail.Framework
import Castle.MonoRail.WindsorExtension
import Castle.Facilities.ActiveRecordIntegration
import Castle.Services.Transaction
import Castle.Facilities.AutomaticTransactionManagement
import Rhino.Commons    from Rhino.Commons
import Rhino.Commons    from Rhino.Commons.ActiveRecord

Facility(	"rails", RailsFacility )
    
Facility( "arintegration", ActiveRecordFacility,
	{ @isWeb: true, @isDebug: true, @pluralizeTableNames: true,
	  assemblies: [ Assembly.Load("Zambezi.Web") ],
	  child(config): { keyvalues(): {
		'show_sql': true,
		'command_timeout': 5000,
		'cache.use_query_cache': false,
		'dialect': 'NHibernate.Dialect.MsSql2005Dialect',
		'connection.provider': 'NHibernate.Connection.DriverConnectionProvider',
		'connection.driver_class': 'NHibernate.Driver.SqlClientDriver',
		'connection.connection_string': 'Data Source=localhost;Initial Catalog=zambezi;Integrated Security=True'
		} }
    } )
    
webAsm = Assembly.Load("Zambezi.Web")

for type in webAsm.GetTypes():
	if typeof(Controller).IsAssignableFrom(type):
		Component(type.Name, type)
	elif typeof(ViewComponent).IsAssignableFrom(type):
		Component(type.Name, type)

Component(	transaction_manager, 
			ITransactionManager, 
			DefaultTransactionManager)

Component(	"entity_repository", 
			Rhino.Commons.IRepository, 
			Rhino.Commons.ARRepository )

Component(	"unit_of_work_factory", 
			Rhino.Commons.IUnitOfWorkFactory, 
			Rhino.Commons.ActiveRecordUnitOfWorkFactory )